#include <cstdio>
#include <queue>
#include <utility>
#include <vector>
#include <cstring>
#include <set>
using namespace std;

#define MAXN 30

#define INF 0x3F3F3F3F

int dir[4][2] = {
    {-1, 0}, {1, 0}, {0, -1}, {0, 1}
};

struct Point {
    int l, r, c, t;
    Point(): l(0), r(0), c(0), t(0) { }
    Point(int l, int r, int c, int t): l(l), r(r), c(c), t(t) { }
};

int L, R, C;
char MAP[MAXN][MAXN][MAXN];
bool BOOK[MAXN][MAXN][MAXN];

int ans;

void BFS(int l1, int r1, int c1, int l2, int r2, int c2) {
    ans = -1;
    memset(BOOK, 0, sizeof(BOOK));
    queue<Point> q;
    q.push(Point(l1, r1, c1, 0));
    BOOK[l1][r1][c1] = true;
    while (!q.empty()) {
        Point p = q.front(); q.pop();
        int l=p.l, r=p.r, c=p.c;
        if (l==l2 && r==r2 && c==c2) {
            ans = p.t;
            return;
        }
        for (int i=0; i<4; i++) {
            int nr = r+dir[i][0];
            int nc = c+dir[i][1];
            if (nr >= 0 && nr < R && nc >= 0 && nc < C) {
                if (MAP[l][nr][nc] != '#' && !BOOK[l][nr][nc]) {
                    q.push(Point(l, nr, nc, p.t+1));
                    BOOK[l][nr][nc] = true;
                }
            }
            if (l-1 >= 0) {
                if (MAP[l-1][r][c] != '#' && !BOOK[l-1][r][c]) {
                    q.push(Point(l-1, r, c, p.t+1));
                    BOOK[l-1][r][c] = true;
                }
            }
            if (l+1 < L) {
                if (MAP[l+1][r][c] != '#' && !BOOK[l+1][r][c]) {
                    q.push(Point(l+1, r, c, p.t+1));
                    BOOK[l+1][r][c] = true;
                }
            }
        }
    }
}



int main()
{
    while (true) {
        scanf("%d%d%d", &L, &R, &C);
        if (L==0 && R==0 && C==0) break;
        getchar();
        int l1, r1, c1, l2, r2, c2;
        for (int i=0; i<L; i++) {
            for (int j=0; j<R; j++) {
                for (int k=0; k<C; k++) {
                    scanf("%c", &MAP[i][j][k]);
                    if (MAP[i][j][k] == 'S') {
                        l1 = i; r1 = j; c1 = k;
                    }
                    if (MAP[i][j][k] == 'E') {
                        l2 = i; r2 = j; c2 = k;
                    }
                }
                getchar();
            }
            getchar();
        }
        BFS(l1, r1, c1, l2, r2, c2);
        if (ans > 0) {
            printf("Escaped in %d minute(s).\n", ans);
        } else {
            printf("Trapped!\n");
        }
    }
    return 0;
}
